#!/usr/bin/python
# -*- coding: utf-8 -*-
"""常量定义相关
"""

class ConstBase(object):
    """常量定义基类
    
    e.g.
    
    class CONSTA(ConstBase):
        AAAA = 'aaaa'
        BBBB = 'bbbb'
    """
    
    @classmethod
    def keys(cls):
        return (v for k, v in cls.__dict__.items() if not k.startswith('_'))
    
    @classmethod
    def has_key(cls, k):
        return k in cls.keys()

class AttrName:
    """属性名基类，封装了根据属性值获取属性名字符串的方法"""
    @classmethod
    def attr_name(cls, attr_val):
        """根据属性值获取属性名字符串"""
        for name in cls.__dict__:
            if attr_val == cls.__dict__[name]:
                return name.replace('_', '')
        print attr_val
        raise ValueError('attr_val: %s' % attr_val)
    
class Test(ConstBase):
    """请求的参数"""
    KEY = 'key'
    GUID = 'g'
    CONTENT = 'c'
    
class FileType(AttrName):
    """已知能根据文件格式判断文件类型的文件类型定义"""
    Permdenied = -3
    Nofile = -2
    Empty = -1
    Unknow = 0
    # PE
    EXE = 1
    DLL = 2
    MSI = 11
    COM = 21
    DOS = 22
    # 压缩包 101开始
    RAR = 101 
    ZIP = 102
    CAB = 103
    ACE = 104
    ARC = 105
    ARJ = 106
    TAR = 107
    Z = 108 #7z
    BIN = 109
    BZ2 = 110
    CUE = 111
    DBX = 112
    DEB = 113
    GZ = 114
    IMG = 115
    JAR = 116
    MSP = 117
    RPM = 118
    TGZ = 119
    ZOO = 120
    _7Z = 121 # 要去掉_
    # 图片 201开始
    JPG = 201
    BMP = 202
    GIF = 203
    PNG = 204
    ICO = 205
    # file, flash
    PDF = 301
    SWF = 302
    # 文本
    TXT = 401
    CVS = 402
    HTML = 411
    HTM = 412
    XML = 413
    JS = 414
    CSS = 415
    LST = 416
    INI = 417
    BAT = 418
    LOG = 419
    # Office
    DOC = 501
    XLS = 502
    PPT = 503
    DOCX = 504
    WPS = 511
    ET = 512
    DPS = 513
    RTF = 514
    # .NET
    CS = 601
    VB = 602
    ASP = 603
    ASPX = 604
    ASCX = 605
    ASHX = 606
    # Python
    PY = 701
    PYC = 702
    PYO = 703
    # Java
    CLASS = 801
    JAVA = 802
    # audio
    MP3 = 901
    WAV = 902
    ASF = 903
    M3U = 904
    MID = 905
    MKV = 906
    VOC = 907
    SND = 908
    SVX = 909
    AIF = 910
    AIFC = 911
    AIFF = 912
    RAM = 913
    # Video
    RMVB = 1001
    RM = 1002
    AVI = 1003
    MP4 = 1004
    MOV = 1005
    MEPG = 1006
    WMV = 1007
    ASF = 1008
    MPG = 1009
    # Other
    AP = 2001
    APP = 2002
    # System
    ACF = 3001
    ACM = 3002
    ACS = 3003
    ANI = 3004
    ANS = 3005
    #临时文件：
    TMP = 4001
    SYD = 4002
#    _'$$$ = 4003
#    _@@@ = 4003
#    _MP = 4004
    GID = 4005
#    ~   = 4006
    GTS = 4007
    #备份文件：
    BAK = 4101
    OLD = 4102
    WBK = 4103
    XLK = 4104
    CKR_ = 4105
    #帮助文件：
    HLP = 4201
    CHM = 4202
    CNT = 4203
    
FileTypeName = dict([(FileType.__dict__[key], key.replace('_', '')) for key in FileType.__dict__])

class FileInfoKey:
    """文件信息字典key"""
    MD5 = u'MD5'
    SHA1 = u'SHA1'
    Comments = u'Comments'
    CompanyName = u'CompanyName'
    FileName = u'FileName'
    FileType = u'FileType'
    FileSize = u'FileSize'
    FileVersion = u'FileVersion'    #文件版本
    FileDescription = u'FileDescription'#描述
    Attribute = u'Attribute'
    InternalName = u'InternalName' #内部名称
    OriginalFilename = u'OriginalFilename' #源文件名
    LegalCopyright = u'LegalCopyright'
    LegalTrademarks = u'LegalTrademarks'
    ProductName = u'ProductName'
    ProductVersion = u'ProductVersion'
    PrivateBuild = u'PrivateBuild'
    SpecialBuild = u'SpecialBuild'          #特别编译版本
    CreatedTime = u'CreatedTime'            #创建时间
    ModifiedTime = u'ModifiedTime'          #修改时间
    AccessedTime = u'AccessedTime'          #访问时间
    Language = u'Language'                  #语言编号
    LanguageName = u'LanguageName'          #语言名
    CodePage = u'CodePage'
    CodePageName = u'CodePageName'
    Status = u'Status' #数字签名有效位, 默认为1: 未验证, 2: 有效, -1: 无效, 0: 没有数字签名
    HasVersionInfo = u'HasVersionInfo'
    DigitalSubject = u'DigitalSubject'
    DigitalIssuer = u'DigitalIssuer'
    DigitalStartDate = u'DigitalStartDate'
    DigitalEndDate = u'DigitalEndDate'
    # ms update package
    AppliesTo = u'Applies to'
    BuildDate = u'Build Date'
    InstallationType = u'Installation Type'
    InstallerEngine = u'Installer Engine'
    InstallerVersion = u'Installer Version'
    KBArticleNumber = u'KB Article Number'
    PackageType = u'Package Type'
    ProcArchitecture = u'Proc. Architecture'
    SelfExtractorVersion = u'Self-Extractor Version'
    SupportLink = u'Support Link'

class FixedFileInfoKey:
    """固定的文件信息字典键"""
    Signature = u'Signature'
    StrucVersion = u'StrucVersion'
    FileVersionMS = u'FileVersionMS'
    FileVersionLS = u'FileVersionLS'
    ProductVersionMS = u'ProductVersionMS'
    ProductVersionLS = u'ProductVersionLS'
    FileFlagsMask = u'FileFlagsMask'
    FileFlags = u'FileFlags'
    FileOS = u'FileOS'
    FileType = u'FileType'
    FileSubtype = u'FileSubtype'
    FileDateMS = u'FileDateMS'
    FileDateLS = u'FileDateLS'
    
class USER(ConstBase):
    """用户信息"""
    USERNAME = 'username'
    PASSWORD = 'password' 
    PERMISSION = 'permission'
    SESSION_ID = 'session_id' 
    
if __name__ == '__main__':
    class CONSTA(ConstBase):
        AAAA = 'aaaa'
        BBBB = 'bbbb'
    print CONSTA.AAAA
    for k in CONSTA.keys():
        print k
        
    print CONSTA.has_key('aaaa')
    
    print FileTypeName[1]
    
    print FileType.JPG